#ifndef FILESYSTEM_H_
#define FILESYSTEM_H_

#include "../../std/file_common.h"

#define OWNER	0
#define GROUP	1
#define OTHER	2

#define READ_PERMISSION 	4
#define WRITE_PERMISSION 	2
#define EXE_PERMISSION 		1

#define FILETABLE_SECTOR_START 20

#define MAX_SECTORS 15000
#define MAX_SECTOR_BYTES (MAX_SECTORS/8)

#define TABLE_STARTUP_SECTOR 10 
#define TABLE_SECTOR_SIZE (MAX_SECTOR_BYTES/512)

#define REF_DATA_CANT ((SECTOR_SIZE-1-sizeof(unsigned int)*2)/sizeof(RefData))

#define TABLE_HEADER "FSYST START"

#define CHILDS_CANT 100


#define FILE_ROOT "Root"


#define EOF -1

typedef struct File File;
struct File {
	char name[FILE_NAME];
	unsigned int sector;
	unsigned int psector;
	unsigned int sectorRefData;
	unsigned int size;	
	unsigned int type;	
	unsigned int count;	
	short int mode;
	char owner[NAME_MAX_LENGTH];
	char group[NAME_MAX_LENGTH];
	File * parent;
	
}__attribute__((packed));

typedef struct File_Disk File_Disk;
struct File_Disk {
	char owner[NAME_MAX_LENGTH];
	char group[NAME_MAX_LENGTH];
	unsigned int sectorRefData;
	unsigned int size;
	unsigned int type;	
	unsigned int count;	
	short int mode;
}__attribute__((packed));

typedef struct RefData RefData;
struct RefData {
	unsigned int sector;
	unsigned int sectorCant;	
}__attribute__((packed));

typedef struct FileData FileData;
struct FileData{
	char data[SECTOR_SIZE-1];
}__attribute__((packed));

typedef struct RefDataSector RefDataSector;
struct RefDataSector {
	unsigned int cant;
	unsigned int next;
	RefData list[REF_DATA_CANT];
}__attribute__((packed));



extern File fileTable[MAX_FILES];

File * create_empty_file(char * name,int mode);

File * getCurrentDir();

File * getFileByPath(File * file, char * path);

void createFilesystem();

int init_filesystem();

int loadFileSystem();

char * getPath();




#endif
